<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    /* 
     手写useState:
     1. 声明一个变量并且可以有有初始值
     2. 保存该变量
     3. 定义方法用来改变变量得值
     4. 将定义得变量和方法返回
    */
    let state;
    function myUseState(initState){
        // initState 默认状态值;
        state = state || initState;
        let setState = (newState)=>{
            state = newState
            ReactDOM.render(<App/>,document.getElementById("root"))
        }
        return [state,setState]
    }
    function App(){
        let [num,setNum] = myUseState(0);
        return (
            <div>
            <h1>{num}</h1>  
            <button onClick={()=>{
                setNum(num+1)
            }}>++</button>   
            </div>
        )
    }
    ReactDOM.render(<App/>,document.getElementById("root"))
    console.log(5>10||"哈哈哈哈")
</script>
</html>